<?php


namespace App\Admin\Forms\Config;


use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;

class SmtpConfig extends ConfigForm implements LazyRenderable
{
    use LazyWidget;

    public static function label() :array
    {
        return [
            "mailer" => "发送方式",
            "transport"=>"传输协议",
            "host"=>"主机地址",
            "port"=>"主机端口",
            "encryption"=>"加密协议",
            "timeout"=>"超时时间",
            "local_domain"=>"发送域名",
            "username" => "账号",
            "password" => "密码",
            "address" => "发件人邮箱",
            "name" => "发件人",
        ];
    }


    public static function mapping() :array
    {
        return [
            "mailer" => "mail.default",
            "transport"=>"mail.mailers.smtp.transport",
            "host"=>"mail.mailers.smtp.host",
            "port"=>"mail.mailers.smtp.port",
            "encryption"=>"mail.mailers.smtp.encryption",
            "timeout"=>"mail.mailers.smtp.timeout",
            "local_domain"=>"mail.mailers.smtp.local_domain",
            "username" => "mail.mailers.smtp.username",
            "password" => "mail.mailers.smtp.password",
            "address" => "mail.from.address",
            "name" => "mail.from.name",
        ];
    }

    /**
     * 构建表单.
     */
    public function form()
    {
        $this->email('address', '发件人邮箱')->required();
        $this->text('name', '发件人')->required();
        $this->divider("Mailer");
        $this->radio("mailer")->options(["smtp"=>"SMTP"])->default("smtp")->when("smtp",function (){
            $this->text('transport',"传输协议")->default("smtp")->readOnly();
            $this->url('host',"主机地址");
            $this->number('port',"主机端口");
            $this->radio('encryption', '加密协议')->required()->options(['tls' => 'TLS']);
            $this->number('timeout', '超时时间')->required();
            $this->url('local_domain', '发送域名')->required();
            $this->text('username', '账号')->required();
            $this->password('password', '密码')->required();
        });

    }
}
